<?php
//声明命名空间
namespace Admin\Controller;
//引入基础控制器
use \Frame\Libs\BaseController;
//引入model
use \Admin\Model\LinksModel;
//声明友情链接类
final class LinksController extends BaseController
{
    public function index()
    {
        $links = LinksModel::getInstance()->fetchAll();
        $this->smarty->assign("links",$links);
        $this->smarty->display("Links/index.html");
    }
    public function del()
    {
        $id = $_GET["id"];
        $links = LinksModel::getInstance()->del($id);
        if($links){
            $this->jump("删除记录为{$id}数据成功","?c=Links");
        }else{
            $this->jump("删除记录为{$id}数据失败","?c=Links");
        }
    }
    public function update()
    {
        $id = $_GET["id"];
        $links = LinksModel::getInstance()->fetchOne("id=$id");
        $this->smarty->assign("id",$id);
        $this->smarty->assign("links",$links);
        $this->smarty->display("Links/update.html");
    }
    public function edit()
    {
        $id = $_POST["id"];
        $domain = $_POST["domain"];
        $url = $_POST["url"];
        $orderby = $_POST["orderby"];
        $links = LinksModel::getInstance()->edit("domain='$domain',url='$url',orderby='$orderby'",$id);
        if($links){
            $this->jump("修改记录为{$id}数据成功","?c=Links");
        }else{
            $this->jump("修改记录为{$id}数据失败","?c=Links");
        }
    }
    public function add()
    {
        $this->smarty->display("Links/add.html");
    }
    public function insert()
    {
        $data["domain"] = $_POST["domain"];
        $data["url"] = $_POST["url"];
        $data["orderby"] = $_POST["orderby"];
        $links = LinksModel::getInstance()->insert($data);
        if($links){
            $this->jump("链接添加成功","?c=Links");
        }else{
            $this->jump("链接添加失败","?c=Links");
        }
    }
}